-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wikidata] Fix ISNI crashing and WP parsing #103
Conversation
fillISNI function ----------------- > Uncaught TypeError: Cannot read properties of undefined (reading 'parentElement') edit-artist.isni_codes-template apparently no longer exists. fillFormFromISNI function ------------------------- > Uncaught TypeError: Cannot read properties of null (reading 'length') When regex does not match, it is null. --- Bugs reported by DenizC and diskotechjam in https://community.metabrainz.org/t/user-script-to-load-artist-data-from-wikipedia/86338/38?u=jesus2099 --- Bonus: Use only UTC time functions everywhere, for consistency
When an ISNI code is already there, it is now trying to add a new. |
Thanks @zas for testing. ❌ BTW I notice that I have indeed removed the 2 ways of systematic crashing the script but ISNI is no longer set at all. ❌ For example I have an artist with no ISRC and the script just adds a second empty ISNI field. So I will fix my fix. But please advise what should be done when:
|
What I meant is it tries to add the same ISNI as it was new (so it displays it as a new field, but doesn't actually add it). About various cases:
Perhaps just warn, but don't add the new one, it might be an error, and we don't know where
Do nothing
Add the one from WD (if any, of course) |
MBS new react-hydrate system makes it so that script added ISNI code will not visually persist if you click "Add ISNI code" button afterwards or things like that. I tested these known react-hydrate-resist tricks but they unfortunately did not work for ISNI codes: https://github.com/jesus2099/konami-command/blob/a1dd018d84cecee965943dda19617a6807dcedc4/lib/SUPER.js#L163-L172 d4c8183
Tested on desktop and mobile Reported by diskotechjam in: https://community.metabrainz.org/t/user-script-to-load-artist-data-from-wikipedia/86338/42?u=jesus2099
I have fixed the WP URL handling (09f3a01) and the actual filling of ISNI code field from WD (582de28), in this same PR proposal. The only problem that remains:
|
I put the PR on hold as I will try my react-hydrate workaround once more, tomorrow. No no, I did already test it well in 582de28 and this react-hydrate workaround doesn't work for ISNI codes, indeed. Last updateProblem fixed by c298541 thanks to https://nattaylor.com/blog/2022/userscripts-and-reactjs-forms/
|
Fixes the small hindrance of visual disappearance of ISNI, when clicking the new ISNI button Hindrance described in 582de28 The trick was to let the input event BUBBLING UP! https://nattaylor.com/blog/2022/userscripts-and-reactjs-forms/
Problem fixed by c298541 thanks to https://nattaylor.com/blog/2022/userscripts-and-reactjs-forms/
|
Hi @Jerome-Roy / @loujine |
Not so cold when volcanoes wake up :) Thanks for your PR, I'll try to take a look this week. I merged some simpler pull requests tonight, ping me if I broke something |
I tried to analyse the merge conflict, please tell me if it's OK for you, @loujine. :) Remaining conflict compareRepo const isniBlock = document.getElementById(
'add-isni-code').parentElement.parentElement;
const fields = isniBlock.getElementsByTagName('input');
for (const input of fields) {
existing_isni.push(input.value.split(' ').join(''));
}
existing_isni.splice(0, 1); // skip template
if (existing_isni.includes(isni.split(' ').join(''))) {
return;
}
if (existing_isni.length === 1 && existing_isni[0] === '') {
document.getElementsByName('edit-artist.isni_codes.0')[0].value = isni; Repo const isni_fields = document.querySelectorAll('input[name^="edit-artist.isni_codes."]');
for (const input of isni_fields) {
if (input.value) {
existing_isni.push(input.value.split(' ').join(''));
}
}
if (existing_isni.length === 0) {
(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(isni_fields[0]), 'value').set).call(isni_fields[0], isni);
isni_fields[0].dispatchEvent(new Event('input', {bubbles: true}));
$('#newFields').append(
$('<dt>', {'text': 'New ISNI code added:'})
).append(
$('<dd>', {'text': isni}).css('color', 'green')
); Break outISNI fields selector
const isniBlock = document.getElementById(
'add-isni-code').parentElement.parentElement;
const fields = isniBlock.getElementsByTagName('input');
This PR branch: const isni_fields = document.querySelectorAll('input[name^="edit-artist.isni_codes."]'); These are doing the same thing, tell me if it's OK to keep this version of the ISNI selector fix, @loujine? TemplateTemplate no longer exists and we should remove the skip:
existing_isni.splice(0, 1); // skip template Removed by this PR. Inform the user of already existing ISNI
if (existing_isni.includes(isni.split(' ').join(''))) {
return;
} This PR informed when same ISNI is already set. Inform the user of new ISNI setThis PR branch: $('#newFields').append(
$('<dt>', {'text': 'New ISNI code added:'})
).append(
$('<dd>', {'text': isni}).css('color', 'green')
); This PR now informs when the new ISNI is being set, like for other attribute changes. Setting value so that it is not hidden later by react-hydrateRepo document.getElementsByName('edit-artist.isni_codes.0')[0].value = isni; Repo (Object.getOwnPropertyDescriptor(Object.getPrototypeOf(isni_fields[0]), 'value').set).call(isni_fields[0], isni);
isni_fields[0].dispatchEvent(new Event('input', {bubbles: true})); Now that pages are using react, it is needed to prevent display bugs (disappearing ISNI when giving Add ISNI button), this way. |
I solved conflict, keeping my ISNI fields selector. |
I'm glad to hear from you, again! :) |
I tested quickly, looks good, thanks so much |
Crash bugs (2) reported and pin-pointed by DenizC and diskotechjam in https://community.metabrainz.org/t/user-script-to-load-artist-data-from-wikipedia/86338/38?u=jesus2099 --- - WD is Wikidata - WP is Wikipedia --- fillISNI function crash ----------------------- > Uncaught TypeError: Cannot read properties of undefined (reading 'parentElement') `edit-artist.isni_codes-template` no longer exists in react version of artist edit page. fillFormFromISNI function crash ------------------------------- > Uncaught TypeError: Cannot read properties of null (reading 'length') When regex does not match, it is `null`. Fill ISNI code from WD ---------------------- This does not work on the new react version of the artist edit page. Reported by @zas Fetch WD page from WP URL ------------------------- It does no longer find WD page from WP URL. Probably WP pages have changed. Reported by diskotechjam --- Bonus: Use only UTC time functions everywhere, for consistency
Crash bugs (2) reported and pin-pointed by DenizC and diskotechjam in https://community.metabrainz.org/t/user-script-to-load-artist-data-from-wikipedia/86338/38?u=jesus2099 --- - WD is Wikidata - WP is Wikipedia --- fillISNI function crash ----------------------- > Uncaught TypeError: Cannot read properties of undefined (reading 'parentElement') `edit-artist.isni_codes-template` no longer exists in react version of artist edit page. fillFormFromISNI function crash ------------------------------- > Uncaught TypeError: Cannot read properties of null (reading 'length') When regex does not match, it is `null`. Fill ISNI code from WD ---------------------- This does not work on the new react version of the artist edit page. Reported by @zas Fetch WD page from WP URL ------------------------- It does no longer find WD page from WP URL. Probably WP pages have changed. Reported by diskotechjam --- Bonus: Use only UTC time functions everywhere, for consistency
Crash bugs (2) reported and pin-pointed by DenizC and diskotechjam in
https://community.metabrainz.org/t/user-script-to-load-artist-data-from-wikipedia/86338/38?u=jesus2099
fillISNI function crash
edit-artist.isni_codes-template
no longer exists in react version of artist edit page.fillFormFromISNI function crash
When regex does not match, it is
null
.Fill ISNI code from WD
This does not work on the new react version of the artist edit page.
Reported by @zas
Fetch WD page from WP URL
It does no longer find WD page from WP URL.
Probably WP pages have changed.
Reported by diskotechjam
Bonus: Use only UTC time functions everywhere, for consistency